package com.example.clxy.controller;

import com.example.clxy.entity.Sycourse;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.PageResult.SycoursePageResult;
import com.example.clxy.result.business.SycourseResult;
import com.example.clxy.service.SycourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author liuhaoqi
 * @Date 2020/8/4 11:54
 * @Version 1.0
 */
@AppToken
@RestController
@RequestMapping("SycourseController")
public class SycourseController {

    @Autowired
    SycourseService sycourseService;

    /**
     * 获取实验课程信息列表
     *
     * @param sycoursecode
     * @param sycoursename
     * @param credit
     * @param sycourseintro
     * @param sycoursetype
     * @param sycourseunit
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("getSycourseList")
    @CrossOrigin
    public PageResult<SycoursePageResult> getSycourseList(String sycoursecode, String sycoursename,
                                                          String credit, String sycourseintro, String sycoursetype,
                                                          String sycourseunit, int page, int pagesize) {
        PageResult<SycoursePageResult> result = sycourseService.getSycourseList(sycoursecode, sycoursename,
                credit, sycourseintro, sycoursetype, sycourseunit, page, pagesize);
        return result;
    }

    /**
     * 新增实验课程
     *
     * @param sycourse
     * @return
     */
    @PostMapping("addSycourse")
    @CrossOrigin
    public WebRestResult addSycourse(@RequestBody Sycourse sycourse) {
        WebRestResult result = sycourseService.addSycourse(sycourse);
        return result;
    }

    /**
     * 更新实验课程
     *
     * @param sycourse
     * @return
     */
    @PostMapping("updateSycourse")
    @CrossOrigin
    public WebRestResult updateSycourse(@RequestBody Sycourse sycourse) {
        WebRestResult result = sycourseService.updateSycourse(sycourse);
        return result;
    }

    @PostMapping("deleteSycourse")
    @CrossOrigin
    public WebRestResult deleteSycourse(String sycourseid) {
        WebRestResult result = sycourseService.deleteSycourse(sycourseid);
        return result;
    }

    @GetMapping("getSycourseById")
    @CrossOrigin
    public SycourseResult getSycourseById(String sycourseid) {
        SycourseResult result = sycourseService.getSycourseById(sycourseid);
        return result;
    }

}
